/*--------------------------------------------------------------------------------------+
|
|     $Source: samples/SampleDgnDbEditor/SampleDgnDbEditor.h $
|
|  $Copyright: (c) 2014 Bentley Systems, Incorporated. All rights reserved. $
|
+--------------------------------------------------------------------------------------*/
#pragma once

#include <MobileDgn/MobileDgnApplication.h>
#include <MobileDgn/MobileDgnL10N.h>
#include <DgnView/AccuDraw.h>
#include <DgnView/AccuSnap.h>
#include <DgnView/IRedraw.h>
#include <DgnPlatform/DgnCore/TextString.h>
#include <DgnPlatform/DgnHandlers/DgnGraphicsElement.h>
#include <DgnPlatform/DgnHandlers/DgnECPersistence.h>
#include <ECObjects/ECSchema.h>
#include <ECObjects/BeXmlCommonGeometry.h>
#include <BeSQLite/ECDb/ECDbTypes.h>
#include <Bentley/BeTimeUtilities.h>

USING_NAMESPACE_BENTLEY_SQLITE
USING_NAMESPACE_BENTLEY_SQLITE_EC
USING_NAMESPACE_EC
USING_NAMESPACE_BENTLEY_DGNPLATFORM
USING_NAMESPACE_BENTLEY_MOBILEDGN

#include "SampleDgnDbEditor.xliff.h"
#include "PhysicalItemHandler.h"
#include "ShippingCrateItemHandler.h"
#include "Shipping%Class%ItemHandler.h"

#if 1
    #define DEBUG_PRINT(...)
#else
    #define DEBUG_PRINT(...) printf(__VA_ARGS__)
#endif

struct MoveShipping%Class%Tool;
struct PlaceShippingCrateTool;
struct PlaceShipping%Class%Tool;

//=======================================================================================
// The portable part of the SampleDgnDbEditor application
// @bsiclass                                                    BentleySystems
//=======================================================================================
struct SampleDgnDbEditorApp : MobileDgnApplication
{
    DEFINE_T_SUPER (MobileDgnApplication)
    friend struct DeleteShippingItemTool;
    friend struct MoveShipping%Class%Tool;
    friend struct PlaceShippingCrateTool;
    friend struct PlaceShipping%Class%Tool;

private:
    static Utf8CP MESSAGE_ProjectSelected()     {return "SampleDgnDbEditor.Message.ProjectSelected";}
    static Utf8CP MESSAGE_SaveView()            {return "SampleDgnDbEditor.Message.SaveView";}
    static Utf8CP MESSAGE_GenerateDrawing()     {return "SampleDgnDbEditor.Message.GenerateDrawing";}
    static Utf8CP MESSAGE_ProjectUndo()         {return "SampleDgnDbEditor.Message.ProjectUndo";}
    static Utf8CP MESSAGE_ProjectRedo()         {return "SampleDgnDbEditor.Message.ProjectRedo";}
    static Utf8CP TOOLID_DeleteShippingItem()   {return "SampleDgnDbEditor.Tool.DeleteShippingItem";}
    static Utf8CP TOOLID_MoveShipping%Class%()     {return "SampleDgnDbEditor.Tool.MoveShipping%Class%";}
    static Utf8CP TOOLID_PlaceShippingCrate()   {return "SampleDgnDbEditor.Tool.PlaceShippingCrate";}
    static Utf8CP TOOLID_PlaceShipping%Class%()    {return "SampleDgnDbEditor.Tool.PlaceShipping%Class%";}

    StatusInt ImportECSchema (WCharCP);

protected:
    virtual Utf8CP _GetApplicationClassName() const override {return "SampleDgnDbEditorApp";}
    virtual void _OnMobileDgnInitialized() override;
    virtual void _OnProjectOpen () override;
    virtual void _OnProjectClose () override;
    virtual bool _OnAbstractUiStateChanged (Utf8CP key) override;
    virtual bool _OnMessageReceived (Utf8CP messageType, JsonValueCR messageObj) override;
    virtual DgnTool* _OnStartTool (MobileDgnViewport&, Utf8CP toolName) override;
    virtual bool _GetUiConfigurationFilePath (BeFileNameR) const override;

public:
    static SampleDgnDbEditorApp& GetApp() {return (SampleDgnDbEditorApp&) App();}
    StatusInt DoSaveView();
    StatusInt DoGenerateDrawing();
    void DoProjectUndo();
    void DoProjectRedo();
};

//=======================================================================================
// Helper methods that are likely to move into the core framework
// @bsiclass                                                    BentleySystems
//=======================================================================================
struct DgnGraphicsUtils : NonCopyableClass
{
    static PhysicalGraphicsPtr CreatePhysicalGraphicsFromPhysicalGeometry (DgnModelR, PhysicalGeometryCR, TransformCR);
    static PhysicalGraphicsPtr GetItemPhysicalGraphics (PhysicalItemHandlerR, DgnModelR, IECInstanceCR);
    static StatusInt InsertItemPhysicalGraphics (ElementId*, PhysicalItemHandlerR, DgnModelR, ECInstanceKeyCR);
    static StatusInt UpdateItemPhysicalGraphics (PhysicalItemHandlerR, DgnModelR, ECInstanceKeyCR, ElementId);
};
